package com.myway.service.ibe.common;

import com.myway.dto.domain.TotalFlyPrice;
import com.myway.dto.ibe_param.TaxPrice;
import com.myway.dto.ibe_param.TicketPrice;
import com.myway.dto.vo.FlySegmentVo;

import java.text.DecimalFormat;
import java.util.List;

/**
 * Created by yufei on 2018/6/9.
 */
public class PNRFN {
    public static String toStringFN(TicketPrice ticketPrice, List<FlySegmentVo> segments, boolean infant){

        DecimalFormat format = new DecimalFormat("###############0.00");
        List<TaxPrice> taxPrices = ticketPrice.getTaxPrices();
        StringBuffer sBuffer=new StringBuffer();
        String currencyCode=ticketPrice.getBaseFareCurrencyCode();
        sBuffer.append("FN");
        boolean rt = false;
        double basePrice  = ticketPrice.getBaseFareAmount();
        if(segments.size()>1){
            rt = true;
            basePrice = basePrice*2;
        }
        if(infant){
            sBuffer.append("/IN");
        }
        //﻿国际 FN/FCNY8820.00/SCNY8820.00/C7.00/XCNY330.00/TXYCNY50.00US/TYCCNY50.00US/﻿TXTCNY230. 00US/ACNY9150.00
        sBuffer.append("/F"+ticketPrice.getBaseFareCurrencyCode()).append(format.format(basePrice));
        //sBuffer.append("/E"+ticketPrice.getEquivFareCurrentyCode()).append(format.format(ticketPrice.getEquivFareAmount()));
        //结算信息，并非所有航空公司均开通该功能。
        sBuffer.append("/S"+ticketPrice.getBaseFareCurrencyCode()).append(format.format(basePrice)).append("/C").append(format.format(0.00*100.0));//没有代理费

        double taxAfter2 = 0.0;
        for(int i = 0; i<taxPrices.size(); i++){

        }
        int index = 0;
        for (TaxPrice taxPrice:taxPrices){
            double tax = taxPrice.getAmount();
            if(rt){
                tax = tax*2;
            }
            if(index<3){
                if(!taxPrice.isEXEMPT()){
                    if(currencyCode.equals(taxPrice.getCurrencyCode())){
                        sBuffer.append("/T").append(taxPrice.getCurrencyCode()).append(format.format(tax)).append(taxPrice.getTaxCode());
                    }else{
                        //转换货币
                        //sBuffer.append("/T").append(taxPrice.getCurrencyCode()).append(format.format(taxPrice.getAmount())).append(taxPrice.getTaxCode());
                    }
                }else{
                    sBuffer.append("/TEXEMPTYQ");
                }
            }
            if(index>=2){
                //統計第二項稅費之後的稅費之和
                taxAfter2 =taxAfter2 + tax;
            }
            index++;
        }
        if(taxPrices.size()>3){
            if(currencyCode.equals(taxPrices.get(0).getCurrencyCode())){
                sBuffer.append("/T").append(taxPrices.get(0).getCurrencyCode()).append(format.format(taxAfter2)).append("XT");
            }else {
//                sBuffer.append("/T").append(taxPrices.get(0).getCurrencyCode()).append(format.format(taxAfter2)).append("XT");
            }
        }
        if(currencyCode.equals(ticketPrice.getTotalFareCurrencyCode())){
            sBuffer.append("/A").append(ticketPrice.getTotalFareCurrencyCode()).append(format.format(basePrice+taxAfter2));
        }else{
            sBuffer.append("/A").append(currencyCode).append(format.format(basePrice+taxAfter2));
        }
        return sBuffer.toString();
    }
    public static String toStringFN(TotalFlyPrice totalFlyPrice, List<TaxPrice> taxPrices, List<FlySegmentVo> segments, boolean infant){

        DecimalFormat format = new DecimalFormat("###############0.00");
        StringBuffer sBuffer=new StringBuffer();
        String currencyCode=segments.get(0).getCurrency();
        String travlType=segments.get(0).getTravlType();
        sBuffer.append("FN");
        boolean rt = false;
        double basePrice  = totalFlyPrice.getAdultAmount();
        if(segments.size()>1&&travlType.equals("RT")){
            rt = true;
            basePrice = basePrice;
        }
        if(infant){
            sBuffer.append("/IN");
        }
        //﻿国际 FN/FCNY8820.00/SCNY8820.00/C7.00/XCNY330.00/TXYCNY50.00US/TYCCNY50.00US/﻿TXTCNY230. 00US/ACNY9150.00
        sBuffer.append("/F"+currencyCode).append(format.format(basePrice));
        //结算信息，并非所有航空公司均开通该功能。
        sBuffer.append("/S"+currencyCode).append(format.format(basePrice)).append("/C").append(format.format(0.00*100.0));//没有代理费

        double taxAfter2 = 0.0;
        int index = 0;
        if(taxPrices.size()>0){
            for (TaxPrice taxPrice:taxPrices){
                double tax = taxPrice.getAmount();
                if(rt){
                    tax = tax;
                }
                if(index<3){
                    if(!taxPrice.isEXEMPT()){
//                    sBuffer.append("/T").append(taxPrice.getCurrencyCode()).append(format.format(tax)).append(taxPrice.getTaxCode());
                    }else{
//                        sBuffer.append("/TEXEMPTYQ");
                    }
                }
                if(index>=2){
                    //統計第二項稅費之後的稅費之和
                }
                taxAfter2 =taxAfter2 + tax;
                index++;
            }
            if(taxPrices.size()>3){
//            sBuffer.append("/T").append(taxPrices.get(0).getCurrencyCode()).append(format.format(taxAfter2)).append("XT");
            }
            //总税费
//            sBuffer.append("/X").append(currencyCode).append(format.format(taxAfter2));
        }
        //总价
        sBuffer.append("/A").append(currencyCode).append(format.format(basePrice));
        return sBuffer.toString();
    }
    public static String toStringFN(TotalFlyPrice totalFlyPrice, List<TaxPrice> taxPrices, List<FlySegmentVo> segments, boolean infant,boolean child){

        DecimalFormat format = new DecimalFormat("###############0.00");
        StringBuffer sBuffer=new StringBuffer();
        String currencyCode=segments.get(0).getCurrency();
        String travlType=segments.get(0).getTravlType();
        sBuffer.append("FN");
        boolean rt = false;
        double basePrice  = totalFlyPrice.getAdultAmount();
        if(child)basePrice=totalFlyPrice.getChildrenAmount();
        if(infant)basePrice=totalFlyPrice.getBabayAmount();
        if(segments.size()>1&&travlType.equals("RT")){
            rt = true;
            basePrice = basePrice;
        }
        if(infant){
            sBuffer.append("/IN");
        }
        //﻿国际 FN/FCNY8820.00/SCNY8820.00/C7.00/XCNY330.00/TXYCNY50.00US/TYCCNY50.00US/﻿TXTCNY230. 00US/ACNY9150.00
        sBuffer.append("/F"+currencyCode).append(format.format(basePrice));
        //结算信息，并非所有航空公司均开通该功能。
        sBuffer.append("/S"+currencyCode).append(format.format(basePrice)).append("/C").append(format.format(0.00*100.0));//没有代理费

        double taxAfter2 = 0.0;
        int index = 0;
        if(taxPrices.size()>0){
            for (TaxPrice taxPrice:taxPrices){
                double tax = taxPrice.getAmount();
                if(rt){
                    tax = tax;
                }
                if(index<3){
                    if(!taxPrice.isEXEMPT()){
//                    sBuffer.append("/T").append(taxPrice.getCurrencyCode()).append(format.format(tax)).append(taxPrice.getTaxCode());
                    }else{
//                        sBuffer.append("/TEXEMPTYQ");
                    }
                }
                if(index>=2){
                    //統計第二項稅費之後的稅費之和
                }
                taxAfter2 =taxAfter2 + tax;
                index++;
            }
            if(taxPrices.size()>3){
//            sBuffer.append("/T").append(taxPrices.get(0).getCurrencyCode()).append(format.format(taxAfter2)).append("XT");
            }
            //总税费
//            sBuffer.append("/X").append(currencyCode).append(format.format(taxAfter2));
        }
        //总价
        sBuffer.append("/A").append(currencyCode).append(format.format(basePrice));
        return sBuffer.toString();
    }
}
